# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-07-04
# @File : 0_login_example.py

import requests
import uuid


def login_by_pwd(mobile, password, app_key, device_identify, retry=5):
    for i in range(retry):
        try:
            res = requests.post(
                url="https://newappuser.jiuxian.com/user/loginUserNamePassWd.htm",
                data={
                    "appKey": app_key,
                    "appVersion": "9.0.30",
                    "areaId": "1166",
                    "channelCode": "0",
                    "cpsId": "xiaomi",
                    "deviceIdentify": device_identify,
                    "deviceType": "ANDROID",
                    "deviceTypeExtra": "0",
                    "equipmentType": "M2007J17C",
                    "netEnv": "wifi",
                    "passWord": password,
                    "screenReslolution": "1080x2189",
                    "supportWebp": "1",
                    "sysVersion": "10",
                    "userName": mobile
                },
                headers={
                    "Content-Type": "application/x-www-form-urlencoded",
                    "secure": "false",
                }
            )
            data_dict = res.json()
            return True, data_dict
        except Exception as e:
            # 记录一条，出问题了。mobile
            pass
    else:
        print("循环次数结束，执行 =>一直有异常")
        return False, None


def run():
    for i in range(10000):
        # app_key = device_identify = str(uuid.uuid4())
        app_key = device_identify = ""
        mobile = "15131259999"
        password = "你的密码.."

        status, data_dict = login_by_pwd(mobile, password, app_key, device_identify)
        if not status:
            continue

        # 后续业务
        print(data_dict)


if __name__ == '__main__':
    run()
